#include <iostream>

using namespace std;

typedef struct LINKNODE {
	int val;
	struct LINKNODE* next;
	
	LINKNODE(int x) {
		val = x;
		next = NULL;
	}
}LinkNode;

LinkNode* ReverseList(LinkNode* head) {
	LinkNode* new_head = NULL;
	
	while(head) {
		LinkNode* next = head->next;
		head->next = new_head;
		new_head = head;
		head = next;
	}
	
	return new_head;
}

int main()
{
	LinkNode a(1);
	LinkNode b(2);
	LinkNode c(3);
	LinkNode d(4);
	LinkNode e(5);
	
	a.next = &b;
	b.next = &c;
	c.next = &d;
	d.next = &e;
	
	LinkNode* head = ReverseList(&a);
	
	while(head) {
		cout << head->val << " ";
		head = head->next;
	}
	
	cout << endl;
	
	return 0;
}